﻿using System;
using System.ComponentModel;
using System.Web.UI.WebControls;
using Ue.Framework.Web;
using Ue.Infrastructure.DomainBase;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Articles;

namespace Ue.Qcdz.UI.Controls
{
    public class ArticleGridView : SkinnedGridView, IArticleDataQuery, Ue.Infrastructure.DomainBase.ISort
    {
        private IArticleRepository repository;

        public ArticleGridView()
        {
            this.repository = RepositoryFactory.GetRepository<IArticleRepository, Article>();
        }

        protected override void GridViewDataBind(object sender, EventArgs args)
        {
            IDataResult<Article> dataResult = this.repository.FindBy(this);

            Repeater repeater = sender as Repeater;
            repeater.DataSource = dataResult.DataObjects;
            repeater.DataBind();
            this.RecordCount = dataResult.RecordCount;
        }

        protected override string GetSkinFileName()
        {
            return "~/Admin/Themes/Skins/Articles/Articles.ascx";

        }










        #region IArticleDataQuery 成员


        private string title;
        public string Title
        {
            get
            {
                if (string.IsNullOrEmpty(this.title))
                {
                    return this.Page.Request.GetQueryValue<string>("Title");
                }
                return this.title;
            }
            set
            {
                this.title = value;
            }


        }
        private string tagId;
        public string TagId
        {
            get
            {
                if (string.IsNullOrEmpty(this.tagId))
                    return Page.Request.GetQueryValue<string>("TagId");
                return this.tagId;
            }
            set { this.tagId = value; }


        }

        private bool isTop;
        [DefaultValue(false)]
        public bool IsTop
        {
            get
            {
                if (this.isTop == false)
                    return Page.Request.GetQueryValue<bool>("IsTop");
                return this.isTop;
            }
            set
            {
                this.isTop = value;
            }
        }


        private bool isUse;
        [DefaultValue(false)]
        public bool IsUse
        {
            get
            {
                if (!this.isUse)
                    return Page.Request.GetQueryValue<bool>("Status");
                return this.isUse;
            }
            set
            {
                this.isUse = value;
            }
        }

        #endregion

        public override ISort Sort
        {
            get
            {
                return this;
            }
            protected set
            {
                base.Sort = value;
            }
        }

        public SortMethod SortType
        {
            set;
            get;
        }



        #region ISort 成员

        public string BuildSortStatement()
        {
            return OrderType.GetSortString(SortType);
        }
        #endregion

        #region IArticleDataQuery 成员


        public string Keyword
        {
            get;
            set;
        }

        private string nodeId;
        public string NodeId
        {
            get
            {
                if (string.IsNullOrEmpty(this.nodeId))
                    return Page.Request.GetQueryValue<string>("NodeId");
                return this.nodeId;
            }
            set { this.nodeId = value; }
        }



        public bool IsImg
        {
            set;
            get;
        }


        private bool _IsFocus;
        public bool IsFocus
        {
            get
            {
                if (this._IsFocus == false)
                    return Page.Request.GetQueryValue<bool>("IsFocus");
                return this._IsFocus;
            }
            set { this._IsFocus = value; }
        }

        [DefaultValue(false)]
        public bool IsShowSgPage { get; set; }

        #endregion
    }
}